﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace inventory.forms
{
    public partial class statementSaleInform : baseStatementInventory
    {
        public statementSaleInform()
        {
            InitializeComponent();
            if(this.dataTabControl.TabPages.Contains(collectPg))
                this.dataTabControl.TabPages.Remove(collectPg);

            this.myAutoEditKeyGroup = "STAMNT_SALEINFORM";
        }

        #region private
        myReports.inventory.printStatementInform myReport = null;
        myReportData myReportTbl = null;
        private void PrintOrderInform(bool fPreview, bool withChildItems)
        {
            data.masterDS.CustomerRow customerInfo = DataAccess.DataCache.FindCUSTOMER(custCodeEd.Text);
            if (customerInfo == null)
            {
                common.SysLibs.ShowErrorMessage("Không có khách hàng " + custCodeEd.Text);
                return;
            }
            if (myReportTbl == null) myReportTbl = new myReportData();
            myReportTbl.Restart();
            GetReportData(myReportTbl, withChildItems);

            if (myReport == null) myReport = new myReports.inventory.printStatementInform();
            //Report parametters
            string[] reportTitle = application.ReportLibs.CompanyHeader(companyCb.myValue);
            string[] workerName = new string[] { CommonTypes.Settings.sysLoginInfo.FullName };

            string[] reportData = new string[]{ 
                    "PHIẾU BÁO ĐẶT HÀNG", editKeyEd.Text, custCodeEd.Text.Trim(), 
                    GetSaleCode4Print() + " ", 
                    customerInfo.name1,customerInfo.address1, 
                    (customerInfo.IsphoneNull()?"":customerInfo.phone),
                    planDateEd.Text,contractNoEd.Text,comment1Ed.Text,noteEd.Text, 
                    application.ReportLibs.SayDate(dateEd.Text)
            };
            myReport.SetDataSource((DataTable)myReportTbl);

            this.SetReport(myReport);
            this.SetReport(reportTitle, "reportTitle");
            this.SetReport(reportTitle, "reportTitle");
            this.SetReport(reportData, "reportData");
            this.SetReport(workerName, "workerName");
            this.SetReport(application.ReportLibs.GetCompanyLogoFile(companyCb.myValue), "logoPath");
            myReportViewer.ShowReport(fPreview);
        }
        #endregion

        protected override void ModifyMenu()
        {
            base.ModifyMenu();
            ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
            ToolStripItem menuItem;
            menuItem = contextMenuStrip.Items.Add("Tổng hợp");
            menuItem.Click += new System.EventHandler(PrintGeneral_Handler);

            menuItem = contextMenuStrip.Items.Add("Chi tiết");
            menuItem.Click += new System.EventHandler(PrintDetail_Handler);
        }
        public override void Print(bool fPreview)
        {
            PrintOrderInform(fPreview, false);
        }

        #region event
        private void PrintGeneral_Handler(object sender, EventArgs e)
        {
            try
            {
                PrintOrderInform(true, false);
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
        private void PrintDetail_Handler(object sender, EventArgs e)
        {
            try
            {
                PrintOrderInform(true, true);
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
        #endregion
    }
}
